package gov.kqqzyyy.monkey.tjpd.mytools;


import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import java.util.concurrent.TimeUnit;

import gov.kqqzyyy.monkey.tjpd.R;
import gov.kqqzyyy.monkey.tjpd.service.APIService;
import okhttp3.OkHttpClient;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.scalars.ScalarsConverterFactory;

/**
 * Created by Monkey on 2017/11/1.
 * Service工具类
 */

public class MyServiceUtil {


    private static SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MyApplication.applicationContext);
    private static String serverAdd = sharedPreferences.getString("server_address", MyApplication.applicationContext.getString(R.string.default_server));
    private static String baseUrl = "http://" + serverAdd + "/api/Query/";

    private static OkHttpClient client = new OkHttpClient.Builder()
            .connectTimeout(20, TimeUnit.SECONDS)
            .readTimeout(20, TimeUnit.SECONDS)
            .writeTimeout(20, TimeUnit.SECONDS)
            .build();
    private static Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(baseUrl)
            .client(client)
            .addConverterFactory(ScalarsConverterFactory.create())
            .build();

    private static APIService apiService = retrofit.create(APIService.class);

    public static Call<String> getSystemTimeCall() {
        return apiService.getSystemTime();
    }

    public static Call<String> getZslbCall() {
        return apiService.getZslb();
    }

    public static Call<String> getZsxxCall(int zsid) {
        return apiService.getZsxx(zsid);
    }

    public static Call<String> getDddlCall(int zsid) {
        return apiService.getDddl(zsid);
    }

    public static Call<String> updateHJ(int zsid){
        return apiService.update(zsid);
    }

//    public static Call<String> getTpxxCall(){
//        return apiService.getTpxx();
//    }
}
